home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / c_text.zip / CPBLK.ASM < prev    next >
Assembly Source File  |  1987-06-10  |  6KB  |  139 lines

  1. ;****** CPBLK *****************************************************************
  2. ;
  3. ;       Copy a screen buffer to display memory without visual "noise"
  4. ;       (C) 1982, 1986 Omniware
  5. ;
  6. ;       Usage:
  7. ;               cpblk(src_os, src_seg, dest_os, dest_seg);
  8. ;               unsigned src_os, src_seg, dest_os, dest_seg;
  9. ;
  10. ;       Notes:
  11. ;       1. Uses calling conventions selected by an equate.
  12. ;       2. Provides the copy function solely for the c/g adapter.  Test
  13. ;          for the required hardware before calling this function.
  14. ;       3. The segments and offsets given in the calling program
  15. ;          determine whether this function does a screen save or a
  16. ;          screen update operation.
  17. ;*****************************************************************************
  18.  
  19. @ab     equ     4       ;small model only
  20. a1      equ     @ab
  21. a2      equ     @ab+4
  22.  
  23. ;-----------video status information-------------
  24. VSTAT   equ     3dah            ; video (CRT) status register
  25. HRTRCE  equ     1               ; horizontal retrace bit mask
  26. VRTRCE  equ     8               ; vertical retrace bit mask
  27. ;-----block data (these values result in 8 extra bytes being copied)----
  28. BLKCNT  equ     6               ; no. of buffer blocks to copy
  29. WRDCNT1 equ     240             ; no. of words to copy during ver. retrace
  30. WRDCNT2 equ     94              ; no. of words to copy during raster scan
  31. BYTECNT equ     2 * WRDCNT2     ; no. of bytes to copy during raster scan
  32.  
  33.         assume  cs:_TEXT
  34. _TEXT   segment byte    public  'CODE'
  35.         public  _cpblk
  36. _cpblk  proc    near
  37.  
  38.         ;-------save registers and flags-----------
  39.         push    bp
  40.         mov     bp,sp
  41.         push    di              ; di and si saved because new C compilers
  42.         push    si              ;    use them for register variables
  43.         push    ds
  44.         push    es
  45.         pushf
  46.  
  47.         ;-------get the source address-------------
  48.         mov     si,a1[bp]
  49.         mov     bx,si
  50.         mov     cl,4            ; shift to extract segment
  51.         shr     bx,cl
  52.         add     bx,a1+2[bp]     ; normalized source segment
  53.  
  54.         ;-------get the destination address--------
  55.         mov     di,a2[bp]
  56.         mov     dx,di
  57.         mov     cl,4            ; shift to extract segment
  58.         shr     dx,cl
  59.         add     dx,a2+2[bp]     ; normalized destination segment
  60.  
  61.         mov     ax,0fh
  62.         and     si,ax           ; source pointer
  63.         and     di,ax           ; destination pointer
  64.  
  65.         cld                     ; set up for auto increment
  66.         mov     ds,bx           ; source segment
  67.         mov     es,dx           ;destination segment
  68.         mov     ah,BLKCNT       ; number of blocks to move
  69.  
  70.         ;-------COPY A BLOCK----------------------------------------------
  71.         ;
  72.         ; The buffer is copied to the display memory in blocks.  Each block
  73.         ; is copied in two parts.  First, a chunk of words (characters and
  74.         ; attributes) is copied during the vertical retrace period and then
  75.         ; individual words are copied during the horizontal retrace periods
  76.         ; of the normal screen update period.  The display is not blanked.
  77.         ;-----------------------------------------------------------------
  78.  
  79. copy_block:
  80.         ;-------copy character/attribute words during vertical retrace----
  81.         mov     cx,WRDCNT1              ; number of words to copy
  82.         mov     dx,VSTAT                ; c/g adapter status register
  83. wait_vert_refresh:
  84.         in      al,dx                   ; read status
  85.         test    al,VRTRCE               ; test vertical retrace bit
  86.         jnz     wait_vert_refresh       ; loop until in a refresh period
  87.  
  88. wait_vert_retrace:
  89.         in      al,dx                   ; read status
  90.         test    al,VRTRCE               ; test vertical retrace bit
  91.         jz      wait_vert_retrace       ; loop until retrace starts
  92.         rep     movsw                   ; move a block of char/attr words
  93.  
  94.         ;-------copy single bytes during horizontal retrace periods-------
  95.         mov     cx,BYTECNT              ; number of bytes to copy
  96.         cmp     cx,0                    ; anything to copy?
  97.         jz      short bypass_horiz      ; no bypass horiz. period updates
  98.         mov     dx,VSTAT                ; read c/g adapter status register
  99.  
  100. wait_horiz_refresh:
  101.         in      al,dx
  102.         test    al,HRTRCE               ; test horizontal retrace bit
  103.         jnz     wait_horiz_refresh      ; loop until not in a retrace period
  104.         cli                             ; can't tolerate an interupt here
  105.  
  106. wait_horiz_retrace:
  107.         in      al,dx
  108.         test    al,HRTRCE               ; test horizontal retrace bit
  109.         jz      wait_horiz_retrace      ; loop until retrace starts
  110.  
  111.         movsb                           ; copy a byte
  112.         sti                             ; interupts OK now
  113.  
  114.         loop    wait_horiz_refresh
  115.  
  116. bypass_horiz:
  117.         ;-------see if all rows have been copied-------------------
  118.         dec     ah                      ; reduce the block count
  119.         cmp     ah,0                    ; done?
  120.         jnz     short copy_block        ; no - do it again
  121.  
  122.         ;-------clean up and return to caller----------------------
  123.         popf                            ; yes - restore flags...
  124.         pop     es
  125.         pop     ds
  126.         pop     si
  127.         pop     di
  128.         pop     bp
  129.         ret
  130.  
  131. _cpblk  endp
  132. _TEXT   ends
  133.         end
  134.  
  135.  
  136.  
  137.  
  138.  
  139.